

<div class="row-fluid">
    <div class="block">
        <p class="block-heading" data-toggle="collapse" data-target="#chart-container">分类添加</p>
        <div id="chart-container" class="block-body collapse in">
            <!-- <div id="line-chart"></div> -->
            <form action="" method="post" accept-charset="utf-8">
              <label>类&nbsp;&nbsp;&nbsp;名：<input type="text" name="name" value=""></label>
              <label class="select">类&nbsp;&nbsp;&nbsp;别：
                                            <select class="pid" name="pid">
                                                <option>—— ——</option>
                                                <option value="1">国内新闻</option>
                                                <option value="2">国际新闻</option>
                                            </select>

              </label>

              <label><input type="submit" name="" value="添加"></label>
            </form>
        </div>
    </div>
</div>
<script src="resources/admin/js/jQuery.js" type="text/javascript"></script>
<script type="text/javascript">

  $(function(){

    $('form').on('change','select',function(){

      $(this).nextAll().remove();


      //var v1 = $(this).find('option:selected').text();
      var v1 = $(this).get(0).selectedIndex;
      if (v1=='0') {

          return false;
      };
      var pid = $(this).val();

      $.ajax({
        url: 'index.php?c=cate&a=add&admin=1',
        type: 'post',
        dataType: 'json',
        data: {'pid': pid},
        success:function(json){
          console.log(json);
          var html = '<select class="pid" name="pid">';
          html += '<option value="'+json[0].pid+'">—— ——</option>';
          for(var i in json){

            html += '<option value="'+json[i].id+'">'+json[i].name+'</option>';

          }

          html += '</select>';
          //console.log(html);
          $('.select').append(html);

        }
      })


    })

  })
</script>


